package com.java.system.service.impl;

import com.java.system.entity.*;
import com.java.system.mapper.EventMapper;
import com.java.system.service.IEventService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-12
 */
@Service
public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements IEventService {
    @Autowired
    EventMapper eventMapper;

    @Override
    public void insertEvent(Event event) {
        eventMapper.insert(event);
    }

    @Override
    public List<Event> getEvent() {
        List<Event> eventList = eventMapper.selectEvent();
        if(!StringUtils.isEmpty(eventList)){
            return eventList;
        }
        else {
            return null;
        }
    }

    @Override
    public Event getEventById(Integer id) {
        Event event = eventMapper.selectById(id);

        if(event!=null){
            return event;
        }else {
            return null;
        }
    }

    @Override
    public void updateEvent(Event event) {
        eventMapper.updateById(event);
    }

    @Override
    public void deleteEvent(Integer id) {
        eventMapper.deleteById(id);
    }

    @Override
    public List<EventType> selectByTime(LocalDateTime startTime, LocalDateTime currentDateTime) {
        List<EventType> eventList = eventMapper.selectByTime(startTime,currentDateTime);
        if(!StringUtils.isEmpty(eventList)){
            return eventList;
        }
        else {
            return null;
        }

    }

    @Override
    public List<ChildEvent> selectChild(LocalDateTime startTime, LocalDateTime currentDateTime) {
        List<ChildEvent> childEventList = eventMapper.selectChild(startTime,currentDateTime);
        if(!StringUtils.isEmpty(childEventList)){
            return childEventList;
        }
        else {
            return null;
        }
    }

    @Override
    public List<EventTime> selectTime(LocalDateTime startTime, LocalDateTime currentDateTime) {
        List<EventTime> timeList = eventMapper.selectTime(startTime,currentDateTime);
        if(!StringUtils.isEmpty(timeList)){
            return timeList;
        }
        else {
            return null;
        }
    }

    @Override
    public List<EventArea> selectArea(LocalDateTime startTime, LocalDateTime currentDateTime) {
        List<EventArea> areaList = eventMapper.selectArea(startTime,currentDateTime);
        if(!StringUtils.isEmpty(areaList)){
            return areaList;
        }
        else {
            return null;
        }
    }

    @Override
    public List<Event> selectCount(LocalDateTime startTime, LocalDateTime currentDateTime) {
        List<Event> eventList = eventMapper.selectCou(startTime,currentDateTime);
        if(!StringUtils.isEmpty(eventList)){
            return eventList;
        }
        else {
            return null;
        }
    }

    @Override
    public List<ChildEvent> selectAllEvent(LocalDateTime startTime, LocalDateTime currentDateTime, String type, Integer areaId) {
        List<ChildEvent> eventList = eventMapper.selectAllCount(startTime,currentDateTime,type,areaId);
        if(!StringUtils.isEmpty(eventList)){
            return eventList;
        }
        else {
            return null;
        }
    }


}
